/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { Request, Response } from 'express';
import { ResponseItem, responseSuccess } from './utils';
import type { HTTableListItem } from '@/pages/CityXLS/HTUpload.d';
import Mock from 'mockjs';

export default {
  'POST /NewRetailSecretLogin/officialList': (req: Request, res: Response, u: string) => {
    let list: Array<HTTableListItem> = [];
    const { page = 1, branch_no } = req.body;
    Array.from({
      length: 20,
    }).map((_, index) => {
      list.push({
        branch_no: index,
        branch_name: `${index}测试测试测试测试`,
        is_open: index % 2 === 0 ? '0' : '1',
      });
    });
    if (branch_no) {
      list = list.filter((item) => item.branch_no == branch_no);
    }

    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: {
        list,
        page: parseInt(page, 10).toString() || '1',
        count: 40,
      },
    };
    return res.json(result);
  },
  'POST /NewRetailSecretLogin/officialHtAddV2': (req: Request, res: Response) =>
    responseSuccess(req, res),

  'POST /NewRetailSecretLogin/officialYTList': (req: Request, res: Response, u: string) => {
    const list: Array<HTTableListItem> = [];
    const { page = 1 } = req.body;
    Array.from({
      length: 5,
    }).map((_, index) => {
      list.push({
        branch_no: index,
        branch_name: `${index}测试测试测试测试`,
        is_open: index % 2 === 0 ? '0' : '1',
      });
    });

    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: {
        list,
        page: parseInt(page, 10).toString() || '1',
        count: 40,
      },
    };
    return res.json(result);
  },
  'POST /NewRetailSecretLogin/officialYTAdd': (req: Request, res: Response) =>
    responseSuccess(req, res),
  'POST /Authorization/authorizationList': (req: Request, res: Response, u: string) => {
    const { page = 1 } = req.body;
    const list = Array.from({ length: 20 }).map((_, index) => {
      return Mock.mock({
        'id|+1': index,
        account: '137****6923',
        smartPlatformName: '@cname',
        kopPhone: '137****6923',
        kopCompayName: '@cwords',
        create_time: '@date',
      });
    });

    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: {
        list,
        page: parseInt(page, 10).toString() || '1',
        count: 40,
      },
    };
    return res.json(result);
  },
  'POST /Authorization/authorizationGetOne': (req: Request, res: Response) => {
    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: {
        id: '61',
        admin_phone: '15201946772',
        account: '18721008363',
        smart_plat_form_name: '快宝急送',
        kop_phone: '15201946772',
        kop_company_name: '现在v重新再v现在陈政旭',
        create_time: '2022-07-06 10:35:25',
      },
    };
    return res.json(result);
  },
  'POST /Authorization/authorizationAdd': (req: Request, res: Response) =>
    responseSuccess(req, res, { wait: 2000 }),
  'POST /Authorization/authorizationDel': (req: Request, res: Response) =>
    responseSuccess(req, res, { wait: 2000 }),
  'POST /Authorization/authorizationExport': (req: Request, res: Response, u: string) => {
    return res.json({
      code: 0,
      msg: '成功',
      data: 'http://upload.kuaidihelp.com/admin/logisticsPortSurvey/csv/开放平台物流接口调查.csv',
    });
  },

  'POST /JtBranch/list': (req: Request, res: Response, u: string) => {
    const list: Array<HTTableListItem> = [];
    const { page = 1 } = req.body;
    Array.from({
      length: 5,
    }).map((_, index) => {
      list.push({
        id: '@id',
        branch_no: index,
        branch_name: `${index}测试测试测试测试`,
        create_time: '@now',
        update_time: '@now',
      });
    });

    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: {
        list,
        page: parseInt(page, 10).toString() || '1',
        count: 40,
      },
    };
    return res.json(result);
  },
  'POST /JtBranch/add': (req: Request, res: Response) => responseSuccess(req, res, { wait: 2000 }),
  'POST /JtBranch/del': (req: Request, res: Response) => responseSuccess(req, res, { wait: 2000 }),
};
